package com.gome.han.bigdata.spark.core.rdd.operation.transformation

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author Hanpeng
 * @date 2021/1/12 22:19
 * @description:
 */
object FlatMapOperation2 {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)

    // TODO 算子 - flatMap
    val rdd = sc.makeRDD(List(List(1,2),3,List(4,5)))

    val flatRDD = rdd.flatMap(
      data => {
        data match {
          case list:List[_] => list
          case dat => List(dat)
        }
      }
    )

    flatRDD.collect().foreach(println)



    sc.stop()
  }
}
